package thread;
//单线程与多线程对比
public class TheadDemo12 {

    public static void main(String[] args) {
        func1();
        func2();
    }

    public static void func1(){
        long beg = System.currentTimeMillis();
        long count1 = 1;
        for (long i = 0; i < 10000_0000; i++) {
            count1++;
        }
        int count2 = 1;
        for (long i = 0; i < 10000_0000; i++) {
            count2++;
        }
        long end = System.currentTimeMillis();
        System.out.println("单线程:"+ (end-beg));
    }

    public static void func2(){

        Thread t1 = new Thread(() ->{
           long count1 = 1;
            for (long i = 0; i < 10000_0000; i++) {
                count1++;
            }
        });

        Thread t2 = new Thread(() ->{
           long count2 = 0;
            for (long i = 0; i < 10000_0000; i++) {
                count2++;
            }
        });
        long beg = System.currentTimeMillis();
        t1.start();
        t2.start();
        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        long end = System.currentTimeMillis();
        System.out.println("双线程:"+(end - beg));
    }
}
